<template>
  <q-page class="cc-admin row">
    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table flat color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" row-key="id" :pagination.sync="pagination" :visible-columns="group" @request="query" :rows-per-page-options="[10, 20, 50, 100]" :selection="mobile ? 'none' : 'multiple'" :selected.sync="selected">
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500" v-model="key">
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
            <table-top-btns label="定时任务" modelName="quartz" :showAdd="true" :table="table" :selected="selected" :importing="importing" :exporting="exporting" :importExcelUrlFull="importExcelUrlFull" :columns="columns" @groupChange="groupChange" @add="add" @importExcel="importExcel" @exportExcel="exportExcel"
              @showConfirm="showConfirm" />
          </div>
        </template>
        <template #body-cell-status="props">
          <q-td key="status" :props="props">{{
            getDictLabel(status, props.row.status)
          }}</q-td>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <cc-btn label="启动" color="primary" icon="not_started" @click="immediateExecution(props.row)"> <q-tooltip>启动</q-tooltip></cc-btn>
            <cc-btn label="编辑" color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></cc-btn>
            <cc-btn label="复制" color="primary" icon="mdi-content-copy" @click="copy(props.row)"> <q-tooltip>复制</q-tooltip></cc-btn>
            <btn-del label @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>
    <cc-dialog ref="dialog" :title="`${editType}`" @submit="submit">
      <div class="col-12">
        <h5>描述：</h5>
        <q-input outlined dense v-model="form.description" type="text" />
      </div>
      <div class="col-12">
        <h5>cron表达式：</h5>
        <q-input outlined dense v-model="form.cronExpression" type="text" />
      </div>
      <div class="col-12">
        <h5>任务类名：</h5>
        <q-input outlined dense v-model="form.jobClassName" type="text" />
      </div>
      <div class="col-12">
        <h5>参数：</h5>
        <q-input outlined dense v-model="form.parameter" type="text" />
      </div>
      <div class="col-12">
        <h5>状态：</h5>
        <q-select outlined dense emit-value v-model="form.status" map-options :options="status" />
      </div>
    </cc-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <confirm ref="copyDialog" icon="mdi-content-copy" color="green" msg="复制这条吗？" @confirm="doCopy()" />
    <cc-loading :loading="loading" />
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import { getDictLabel } from 'boot/dictionary';
import confirm from 'components/confirm';

export default {
  name: 'SysQuartzJob',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      copyRow: null,
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'cronExpression', align: 'center', label: 'cron表达式', field: 'cronExpression',
        },
        {
          name: 'description', align: 'center', label: '描述', field: 'description',
        },
        {
          name: 'jobClassName', align: 'center', label: '任务类名', field: 'jobClassName',
        },
        {
          name: 'parameter', align: 'center', label: '参数', field: 'parameter',
        },
        {
          name: 'status', align: 'center', label: '状态', field: 'status',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'opt',
        },
      ],
      status: [{ value: -1, label: '停止' }, { value: 0, label: '正常' }],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/sys/quartzJob/list',
        add: '/sys/quartzJob/add',
        edit: '/sys/quartzJob/edit',
        copy: '/sys/quartzJob/copy',
        delete: '/sys/quartzJob/delete',
        deleteBatch: '/sys/quartzJob/deleteBatch',
        exportXlsUrl: '/sys/quartzJob/exportXls',
        importExcelUrl: '/sys/quartzJob/importExcel',
      },
    };
  },
  methods: {
    copy(p) {
      this.copyRow = p;
      this.$refs.copyDialog.show();
    },
    doCopy() {
      this.$axios.get(`${this.url.copy}?id=${this.copyRow.id}`, {}).then((r) => {
        this.$info(r.message);
        this.query();
      }).finally(() => {
      });
    },
    addBefore() {
      this.form.catalogId = this.catalog;
      return true;
    },
    selectCatalog(n) {
      this.catalog = n;
      this.query();
    },
    getDictLabel,
    initDict() {
    },
    immediateExecution(row) {
      this.$axios.get(`/sys/quartzJob/execute?id=${row.id}`).then((r) => { });
    }
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
